import React, {Component} from 'react';

class App extends Component {
    state = {
        isShow: true
    }
    render() {
        return (<div>
            <button onClick={() => this.setState({isShow: false})}>click</button>
            {this.state.isShow && <Child/>}
        </div>);
    }
}

class Child extends Component {

    componentDidMount() {
        this.interval = setInterval(() => {
            console.log("11111")
        }, 1000);
    }

    render() {
        return <div>
            child
        </div>
    }

    // 销毁前执行 可用于清除一些计时器和事件监听器
    componentWillUnmount() {
        clearInterval(this.interval)
    }
}

export default App;